import java.security.MessageDigest;
import java.io.OutputStream;

public class HashChain {
	
	//s = sequence number, u = username, p = part number, ops = operation, hmac = hmac of contents of file,
	//prev_h = previous hash chain value
	public static byte[] generateHashChainValue(float partNo, int seqNo, String username, int ops, byte[] HMAC, byte[] prev_h){
		StringBuffer sb = null;
	
		if(prev_h == null)
			prev_h = new byte[16];
		
		//concatenate values		
		String concetenatedString = (Float.toString(partNo) + " " + Integer.toString(seqNo) + " " + username
				+ " " + Integer.toString(ops)+ " " + HMAC + " " + prev_h);
		System.out.println("c string: " + concetenatedString);

        try{
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(concetenatedString.getBytes(), 0, concetenatedString.length());
            byte[] mdbytes = md.digest();

            return mdbytes; 
        }catch (Exception ex) {
            // Do exception handling
        	return null;
        }              
	}	
	
	public static void main(String args[]){
		byte[] curr_h;
		
		curr_h = generateHashChainValue(1, 5, "Bob", 0, null, null);
		
		System.out.println("current hash " + curr_h);
	}
		
}
